/**
 * 
 */
package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.engine.net.GameProtocol;
import com.handinfo.game.ActorItem;
import com.handinfo.game.ActorRole;
import com.handinfo.game.MailItem;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.Tools;

/**
 * @author venizeng
 * 
 */
public class UINpcShop extends UIAbstractWindow implements ILBHandler
{
	/*************************/
	// SYSTEM
	/*************************/
	private final int STATE_SAIL = 1;
	private final int STATE_BUY = 2;
	private final int STATE_FIX = 3;
	private final int STATE_NUM = 4;// 输入文字
	//
	private String TITLE;
	private String DESCRIBE;// Npc描述
	private int NUM;//
	private int STATE_CURRENT;// 再创建对象的时候需要对其进行保存，以防止输入数字之后不知道如何回退
	/*************************/
	// ALL
	/*************************/
	private final int W_BG = UITools.W_BG;// 界面的宽度
	private final int H_BG = UITools.H_BG;// 界面的高度
	private final int H_PRE = AbstractGameScreen.FONT_H;// 一行的高度，价格的高度
	private final int X_BORDER_RECT = 10;// 价格框和描述框距离边框的位置
	private final int X_RECT_CONTENT = 5;// 价格框和描述框距离内容框的位置
	private final int W_PRICE_RECT = W_BG - (X_BORDER_RECT << 1);// 价格框宽度
	private final int W_PRICE_CONTENT = W_PRICE_RECT - (X_RECT_CONTENT << 1);// 价格框内容层宽度
	private final int H_PRICE_RECT = H_PRE + (X_RECT_CONTENT << 1);// 价格框高度
	private final int W_DESCRIBE_RECT = W_PRICE_RECT;
	private final int W_DESCRIBE_CONTENT = W_PRICE_CONTENT;
	private final int H_MONEY_GAME = UITools.H_MONEY_GAME + 2;
	private final int H_MONEY_RMB = UITools.H_MONEY_RMB + 2;
	//
	private final String PRICE = "价格：";
	private long m_price;// 商品价格
	/*************************/
	// BUY-VARS
	/*************************/
	private final int NUM_BUY_ROWS = 3;
	private final int NUM_BUY_COLS = 9;
	//
	private final int IW_BUY_ITEM = 2;// 购买界面 背包格子之间的间隔
	private final int IH_BUY_ITEM = 5;// 购买界面 背包格子之间的间隔
	private final int RW_BUY_ITEM = UITools.W_BAG + IW_BUY_ITEM;
	private final int RH_BUY_ITEM = UITools.H_BAG + IH_BUY_ITEM;
	private final int H_LB = RH_BUY_ITEM * NUM_BUY_ROWS - IH_BUY_ITEM;
	//
	private final int X_BUY_ITEM = ((W_BG - RW_BUY_ITEM * NUM_BUY_COLS - IW_BUY_ITEM) >> 1);// 居中
	private final int Y_BUY_ITEM = UITools.INITY_CONTENT;
	private final int Y_BUY_PRICE = Y_BUY_ITEM + NUM_BUY_ROWS * RH_BUY_ITEM;
	private final int Y_BUY_DESCRIBE = Y_BUY_PRICE + H_PRICE_RECT + UITools.IH_RECT_CONTENT;
	private final int NUM_BUY_DESCRIBE = (UITools.H_RECT - (H_LB + UITools.IH_RECTS)
			- (H_PRICE_RECT + UITools.IH_RECTS)
			- (H_MONEY_GAME + UITools.IH_RECTS))
			/ AbstractGameScreen.FONT_H;// 能显示X行
	private final int H_BUY_DESCRIBE = NUM_BUY_DESCRIBE * AbstractGameScreen.FONT_H + (UITools.IH_RECT_CONTENT << 1);
	//
	private ActorItem[] m_items_buy;
	private byte[] m_buy_i_type_bangdings; // 道具绑定类型
	private short[] m_buy_i_levels;// 道具品级
	private long[] m_buy_i_time_limits;// 道具的时间限制
	private short[] m_buy_i_level_limits;// 道具的等级限制
	private byte[] m_buy_i_career_limits;// 道具的职业限制
	private short[] m_buy_i_naijiu;// 道具的耐久
	private byte[] m_buy_i_pos;// 道具的绑定位置
	//
	private String[] m_buy_s_type_bangdings;// 道具绑定类型
	private String[] m_buy_s_levels;// 道具品级
	private String[] m_buy_s_time_limits;// 道具的时间限制
	private String[] m_buy_s_level_limits;// 道具的等级限制
	private String[] m_buy_s_career_limits;// 道具的职业限制
	private String[] m_buy_s_najius;// 道具的耐久
	private String[] m_buy_s_pos;// 道具的绑定位置
	private String[] m_buy_s_types;// 道具类型

	/*************************/
	// SAIL-VARS
	/*************************/
	private final int GROUP_SAIL_LABEL = 1;
	private final int GROUP_SAIL_BAG = 2;

	private byte TYPE_SHOP;//
	//
	// private final int H_SAIL_DESCRIBE = 3 * H_PRE + (UITools.IH_RECT_CONTENT << 1);// 能显示3行
	//
	private final int Y_SAIL_LABEL = Y_BUY_ITEM;
	// private final int Y_SAIL_DESCRIBE = Y_SAIL_PRICE + H_PRICE_RECT + UITools.IH_RECT_CONTENT;
	//
	private ActorItemLBHandler m_bag_handler;
	/*************************/
	// Fix-VARS
	/*************************/
	private String[] STRS_FIX_DESCRIBE;
	//
	// private final int W_FIX_DESCRIBE_CONTENT = W_PRICE_CONTENT;
	private final int W_FIX_RECT = W_PRICE_RECT;
	private final int H_FIX_RECT = 140;
	private final int W_FIX_BUTTON = 140;
	private final int H_FIX_BUTTON = UITools.H_LABEL;
	private final int IH_FIX_BUTTON = 10;
	//
	private final int X_FIX_DESCRIBE = X_BORDER_RECT + X_RECT_CONTENT;
	private final int Y_FIX_DESCRIBE = Y_BUY_ITEM;
	//
	private final int X_FIX_RECT = ((W_BG - W_FIX_RECT) >> 1);
	private final int Y_FIX_RECT = Y_FIX_DESCRIBE + 2 * H_PRE + UITools.IH_RECT_CONTENT;

	private final int X_FIX_BUTTON1 = X_FIX_RECT + ((W_FIX_RECT - W_FIX_BUTTON) >> 1);
	private final int Y_FIX_BUTTON1 = Y_FIX_RECT + ((H_FIX_RECT - ((H_FIX_BUTTON + H_PRE) << 1) - IH_FIX_BUTTON) >> 1);
	//
	private final int X_FIX_BUTTON2 = X_FIX_BUTTON1;
	private final int Y_FIX_BUTTON2 = Y_FIX_BUTTON1 + (H_FIX_BUTTON + H_PRE + IH_FIX_BUTTON);
	//
	private long m_fix_money_equip;
	private long m_fix_money_all;
	/*************************/
	// NUM-VARS
	/*************************/
	final int W_NUM_INPUT = 30;
	final int H_NUM_INPUT = H_PRE + (UITools.IH_RECT_CONTENT << 1);
	final int IW_NUM_ARR_RECT = 9;// 左右间隔，左右为0 最小为8
	final int IH_NUM_ARR_RECT = 1;
	final int W_DARK = UIManager.IMAGE_ARR_DARK.getWidth();
	final int H_DARK = UIManager.IMAGE_ARR_DARK.getHeight();
	//
	private int m_num_input;// 購買或者出售商品的数目
	private int m_num_max;// 購買或者出售商品的最大数目
	private ActorItem m_num_item;// 購買或者出售商品的最大数目
	private long m_num_money;

	public UINpcShop(int id)
	{
		super(id);
		setBounds(UITools.X_BG, UITools.Y_BG, W_BG, H_BG);
	}

	public static final void test(int state)
	{
		UINpcShop npcShop = new UINpcShop(-1);
		switch (state) {
			case 1:
				npcShop.m_items_buy = ActorItem.getTestItems(27);// 数据设置需要在状态设置之前
				npcShop.setWindowStatus(npcShop.STATE_BUY);
				break;
			case 2:
				npcShop.setWindowStatus(npcShop.STATE_SAIL);
				break;
			case 3:
				npcShop.setWindowStatus(npcShop.STATE_FIX);
				npcShop.STRS_FIX_DESCRIBE = new String[] { "修理", "" };
				break;
			default:
				npcShop.gotoNumInput(20, 10, ActorItem.getTestItem(ActorItem.TYPE_BAG_ROLE, 20));
				break;
		}
		UIManager.getInstance().addWindow(npcShop);
	}

	public static final void recvNpcShopInfos(DataInputStream dis)
	{
		Tools.debugPrintln("readNpcShopInfos");
		try {
			byte state = dis.readByte();
			if (state == 0) {
				return;
			}
			UINpcShop shop = (UINpcShop) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_NPCSHOP);
			if (shop != null) {
				return;
			}
			shop = (UINpcShop) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_NPCSHOP);
			shop.TITLE = dis.readUTF();
			shop.DESCRIBE = dis.readUTF();
			shop.TYPE_SHOP = dis.readByte();
			int size = shop.NUM_BUY_ROWS * shop.NUM_BUY_COLS;
			ActorItem[] item = new ActorItem[size];
			byte[] type_bangdings = new byte[size];
			short[] levels = new short[size];
			long[] time_limits = new long[size];
			short[] level_limits = new short[size];
			byte[] career_limits = new byte[size];
			short[] naijiu = new short[size];
			byte[] pos = new byte[size];
			//
			int num = dis.readInt();
			if (num > size) {
				throw new IllegalArgumentException("数目过大 " + num);
			}
			shop.NUM = num;
			for (int i = 0; i < num; i++) {
				item[i] = new ActorItem();
				item[i].m_key = dis.readUTF();
				item[i].m_num = dis.readInt();// 总数目
				item[i].m_iconId = dis.readShort();
				item[i].m_iconCoverId = dis.readShort();
				item[i].m_name = dis.readUTF();
				item[i].m_describe = dis.readUTF();
				// 绑定类型
				type_bangdings[i] = dis.readByte();
				// 价格
				item[i].m_money_sail = dis.readLong();
				// 品级
				levels[i] = dis.readShort();
				// 使用期限
				time_limits[i] = dis.readLong();
				// 類型
				item[i].m_type = dis.readByte();
				item[i].m_type_detail = dis.readByte();
				// 等級限制
				level_limits[i] = dis.readShort();
				// 职业限制
				career_limits[i] = dis.readByte();
				// 耐久
				naijiu[i] = dis.readShort();
				// 裝備部位
				pos[i] = dis.readByte();
			}
			shop.m_items_buy = item;
			shop.m_buy_i_career_limits = career_limits;
			shop.m_buy_i_level_limits = level_limits;
			shop.m_buy_i_levels = levels;
			shop.m_buy_i_naijiu = naijiu;
			shop.m_buy_i_pos = pos;
			shop.m_buy_i_time_limits = time_limits;
			shop.m_buy_i_type_bangdings = type_bangdings;
			shop.setWindowStatus(shop.STATE_BUY);
			shop.setWindowIndex(0);
			shop.initBuyInfos();
			UIManager.getInstance().addWindow(shop);
		}
		catch (Exception e) {
			e.printStackTrace();
			Tools.debugPrintln("读取商店数据出错");
		}
	}

	/**
	 * 进入商店 2012-2-29 上午10:44:18 venizeng
	 * @throws IOException
	 */
	public static final void recvMessage(int orderId, DataInputStream dis) throws IOException
	{
		UINpcShop npcShop = (UINpcShop) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_NPCSHOP);
		if (npcShop != null) {
			switch (orderId) {
				case GameProtocol.SC_NPC_SHOP_BUY:
					npcShop.recvNpcshopBuy(dis);
					break;
				case GameProtocol.SC_NPC_SHOP_SAIL:
					npcShop.recvNpcshopSail(dis);
			}
		}
	}

	private void recvNpcshopBuy(DataInputStream dis) throws IOException
	{
		byte state = dis.readByte();
		switch (state) {
			case 0:
				return;
			case 1:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "购买成功");
				break;
			case 2:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "道具不存在");
				break;
			case 3:
				String temp = TYPE_SHOP == ActorRole.ZHANGONG ? "战功不足" : "金钱不足";
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, temp);
				break;
			case 4:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "背包已满");
				break;
			case 5:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "背包已满，请扩充背包");
				break;
			default:
				break;
		}
	}

	private void recvNpcshopSail(DataInputStream dis) throws IOException
	{
		byte state = dis.readByte();
		switch (state) {
			case 0:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "出售失败");
				break;
			case 1:
				// 贩卖成功
				int index = dis.readInt();
				GameManager.getInstance().m_role
						.removeActorItemFromBag(GameManager.getInstance().m_role.m_bag_goods[index]);
				break;
			default:
				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "道具不可出售");
				break;
		}
	}

	/**
	 * 进入卖商店 2012-3-12 下午01:43:55 venizeng
	 */
	public static final void recvOpenSailShop(DataInputStream dis)
	{
		try {
			byte state = dis.readByte();
			if (state == 0) {
				return;
			}
			if (UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_NPCSHOP) != null) {//重复打开，因网络延时连续点击多次
				return;
			}
			UINpcShop shop = (UINpcShop) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_NPCSHOP);
			shop.setWindowStatus(shop.STATE_SAIL);
			shop.setWindowIndex(ActorItemLBHandler.NUM_LABEL_DIS);
		}
		catch (IOException e) {
			Tools.debugPrintln("开启贩卖商店出错");
		}
	}

	/**
	 * 2012-3-12 下午01:33:13 venizeng
	 * @param dis
	 */
	public static final void recvOpenFixShop(DataInputStream dis)
	{
        //zuobi 挂机
		if(ActorRole.m_guaji){
			return;
		}
		try {
			byte state = dis.readByte();
			if (state == 1) {
				long m_fix_money_equip = dis.readLong();
				long m_fix_money_all = dis.readLong();
				UINpcShop shop = (UINpcShop) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_NPCSHOP);
				if (shop == null) {
					shop = (UINpcShop) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_NPCSHOP);
				}
				shop.setWindowStatus(shop.STATE_FIX);
				shop.m_fix_money_equip = m_fix_money_equip;
				shop.m_fix_money_all = m_fix_money_all;
			}
		}
		catch (Exception e) {
			Tools.debugPrintln("接收修理界面开启出错");
		}
	}

	/**
	 * 修理单件道具 2012-3-12 下午01:37:22 venizeng
	 * @param dis
	 */
	public static void recvFixEquip(DataInputStream dis)
	{
		try {
			byte state = dis.readByte();
			switch (state) {
				case 0:
					// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "修理失败");
					break;
				case 1:
				default:
					GameManager.getInstance().m_role.m_isNeedFix = false;
					// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "修理成功");
					break;
			}
		}
		catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 修理装备栏道具 2012-3-12 下午01:37:22 venizeng
	 * @param dis
	 */
	public static void recvFixEquips(DataInputStream dis)
	{
		try {
			byte state = dis.readByte();
			switch (state) {
				case 0:
					// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "修理装备栏装备失败");
					break;
				case 1:
				default:
					GameManager.getInstance().m_role.m_isNeedFix = false;
					// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "修理装备栏装备成功");
					break;
			}
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 2012-3-12 下午01:37:22 venizeng
	 * @param dis
	 */
	public static void recvFixAll(DataInputStream dis)
	{
		try {
			byte state = dis.readByte();
			switch (state) {
				case 0:
					// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "修理所有道具失败");
					break;
				case 1:
				default:
					GameManager.getInstance().m_role.m_isNeedFix = false;
					// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "修理所有道具成功");
					break;
			}
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}

	protected void actionOnStateChanged()
	{
		switch (m_state) {
			case STATE_BUY:
				TITLE = "购买商店";
				STATE_CURRENT = m_state;// 保存当前状态
				break;
			case STATE_SAIL:
				TITLE = "出售商店";
				if (m_bag_handler == null) {
					m_bag_handler = new ActorItemLBHandler(this);
					m_bag_handler.setLabelByGroupIndex(0);
				}
				STATE_CURRENT = m_state;
				break;
			case STATE_FIX:
				TITLE = "修理商店";
				STRS_FIX_DESCRIBE = new String[] { "", "" };
				break;
		}
	}

	protected void actionOnIndexChanged()
	{
		switch (m_state) {
			case STATE_BUY: {
				ActorItem item = m_items_buy[m_index];
				if (item == null) {
					m_price = 0;
				}
				else {
					m_price = item.m_money_sail;
				}
			}
				break;
			case STATE_SAIL: {
				m_bag_handler.updateOnStateOrIndexChanged();
				switch (m_groupId) {
					case GROUP_SAIL_BAG:
						ActorItem item = (ActorItem) m_bag_handler.getCurrentBagItem();
						if (item == null) {
							m_price = 0;
						}
						else {
							m_price = item.m_money_sail;
						}
						break;
					default:
						m_price = 0;
						break;
				}
			}
				break;
			case STATE_FIX:
				break;
		}
	}

	protected int countGroupId(int mIndex)
	{
		switch (m_state) {
			case STATE_BUY:
				break;
			case STATE_SAIL:
				if (mIndex < ActorItemLBHandler.NUM_LABEL_DIS) {
					return GROUP_SAIL_LABEL;
				}
				else {
					return GROUP_SAIL_BAG;
				}
			case STATE_FIX:
				break;
		}
		return 0;
	}

	protected int countGroupIndex(int mGroupId, int mIndex)
	{
		switch (m_state) {
			case STATE_BUY:
				break;
			case STATE_SAIL:
				switch (mGroupId) {
					case GROUP_SAIL_LABEL:
						return mIndex;
					case GROUP_SAIL_BAG:
					default:
						return mIndex - ActorItemLBHandler.NUM_LABEL_DIS;
				}
			case STATE_FIX:
				break;
		}
		return 1;
	}

	protected void keyLogic()
	{
		switch (m_state) {
			case STATE_BUY:
				keyLogicOnBuy();
				break;
			case STATE_SAIL:
				keyLogicOnSail();
				break;
			case STATE_FIX:
				keyLogicOnFix();
				break;
			case STATE_NUM:
				keyLogicOnNum();
				break;
		}
	}

	private void initBuyInfos()
	{
		final String STR_BANGDING0 = "不绑定";
		final String STR_BANGDING1 = "装备后绑定";
		final String STR_BANGDING2 = "拾取后绑定";
		final String STR_BANGDING3 = "使用后绑定";
		final String STR_TIME_LIMIT = "不限时间";
		final String STE_LEVEL_START = "等级限制：";
		final String STR_LEVEL_END = "级";
		m_buy_s_type_bangdings = new String[NUM];
		m_buy_s_levels = new String[NUM];
		m_buy_s_time_limits = new String[NUM];
		m_buy_s_level_limits = new String[NUM];
		m_buy_s_career_limits = new String[NUM];
		m_buy_s_najius = new String[NUM];
		m_buy_s_pos = new String[NUM];
		m_buy_s_types = new String[NUM];
		for (int i = 0; i < NUM; i++) {
			// 绑定类型
			switch (m_buy_i_type_bangdings[i]) {
				case 0:
					m_buy_s_type_bangdings[i] = STR_BANGDING0;
					break;
				case 1:
					m_buy_s_type_bangdings[i] = STR_BANGDING1;
					break;
				case 2:
					m_buy_s_type_bangdings[i] = STR_BANGDING2;
					break;
				case 3:
					m_buy_s_type_bangdings[i] = STR_BANGDING3;
					break;
			}
			// 品阶
			m_buy_s_levels[i] = m_buy_s_levels[i];
			// 时间限制
			if (m_buy_i_time_limits[i] == 0) {
				m_buy_s_time_limits[i] = STR_TIME_LIMIT;
			}
			else {
				m_buy_s_time_limits[i] = MailItem.getTime(m_buy_i_time_limits[i]);
			}
			// 类型
			m_buy_s_types[i] = ActorItem.getActorItemTypeName(m_items_buy[i].m_type, m_items_buy[i].m_type_detail);
			if (m_buy_i_level_limits[i] != 0) {
				m_buy_s_level_limits[i] = STE_LEVEL_START + m_buy_i_level_limits[i] + STR_LEVEL_END;
			}
			// 职业限制，仅装备
			if (m_buy_i_career_limits[i] != 0) {
				m_buy_s_career_limits[i] = ActorRole.ROLE_VOCATION_LIST[m_buy_i_career_limits[i]];
			}
			// 耐久，仅装备
			if (m_buy_i_naijiu[i] != 0) {
				// m_buy_s_najius[i] = "耐久：" + m_buy_i_naijiu[i] ;
			}
			// 装备部位，仅装备
			if (m_items_buy[i].m_type == ActorItem.TYPE_GOODS_EQUIPMENT) {
				m_buy_s_pos[i] = ActorItem.getPos(m_buy_i_pos[i]);
			}
		}
	}

	/*************************/
	// BUY-VARS
	/*************************/
	private void keyLogicOnBuy()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			if (m_index < NUM_BUY_COLS) {
				setWindowIndex(m_index + (NUM_BUY_ROWS - 1) * NUM_BUY_COLS);
			}
			else {
				setWindowIndex(m_index - NUM_BUY_COLS);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			if (m_index >= (NUM_BUY_ROWS - 1) * NUM_BUY_COLS) {
				setWindowIndex(m_index - (NUM_BUY_ROWS - 1) * NUM_BUY_COLS);
			}
			else {
				setWindowIndex(m_index + NUM_BUY_COLS);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
			if (m_index % NUM_BUY_COLS == 0) {
				setWindowIndex(m_index + NUM_BUY_COLS - 1);
			}
			else {
				setWindowIndex(m_index - 1);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
			if (m_index % NUM_BUY_COLS == NUM_BUY_COLS - 1) {
				setWindowIndex(m_index - (NUM_BUY_COLS - 1));
			}
			else {
				setWindowIndex(m_index + 1);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			if (m_items_buy[m_index] == null) {
				return;
			}
			final UIPopmenu popmenu = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
			popmenu.setPopmenus(new String[] { "购买", "详情", "返回" });
			popmenu.addListener(new UIListener() {

				public void actionPerformed()
				{
					if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
							|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
						int index = popmenu.getCurrentIndex();
						switch (index) {
							case 0:
								gotoNumInput(99, 1, m_items_buy[m_index]);
								UIManager.getInstance().removeWindow(popmenu);
								break;
							case 1:
								GameManager.getInstance().m_game_message
										.sendActorItemDetail(m_items_buy[m_index].m_key);
								UIManager.getInstance().removeWindow(popmenu);
								break;
							case 2:
								UIManager.getInstance().removeWindow(popmenu);
								break;
						}
					}
					else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
						UIManager.getInstance().removeWindow(popmenu);
					}
				}
			});
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			close();
		}
	}

	/*************************/
	// SAIL-VARS
	/*************************/
	private void keyLogicOnSail()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			close();
			return;
		}
		switch (m_groupId) {
			case GROUP_SAIL_LABEL: {
				int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_LABEL);
				switch (dir) {
					case AbsLBHandler.TYPE_DIR_UNPRO:
						break;
					case AbsLBHandler.TYPE_DIR_NONE:
						// 未处理
						break;
					default:// 有返回值
						this.setWindowIndex(dir);
						break;
				}
			}
				break;
			case GROUP_SAIL_BAG:
			default: {
				int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_BAG);
				switch (dir) {
					case AbsLBHandler.TYPE_DIR_UNPRO:
						break;
					case AbsLBHandler.TYPE_DIR_NONE:
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
							ActorItem item = (ActorItem) m_bag_handler.getCurrentBagItem();
							if (item == null) {
								return;
							}
							if (!item.isCanDealWithNpc()) {
								GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "该道具不可出售");
								return;
							}
							if (item != null) {
								if (item.m_num == 1) {
									sendSail(item);
								}
								else {
									gotoNumSail(item);
								}
							}
						}
						break;
					default:// 有返回值
						this.setWindowIndex(dir);
						break;
				}
			}
				break;
		}
	}

	/**
	 * 进入拆分道具
	 * 2012-4-12 下午06:48:55
	 * venizeng
	 * @param item
	 */
	private void gotoSplitForm(final ActorItem item)
	{
		UIBag.actionSplit(item);
	}

	private void sendSail(ActorItem item)
	{
		if (item.isCanDealWithNpc()) {
			sendSails(item.m_layer_actorItem, item.m_index, item.m_num);
		}
		else {
			GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,
					ActorItem.getOperTypeErrStr(ActorItem.INDEX_TYPE_OPER_DEAL_WITH_NPC));
		}
	}

	private void sendSails(final byte layer, final int index, final int num)
	{
		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_MESSAGEBOX);
		messageBox.setMessage("您确认要出售该道具吗?");
		messageBox.addListener(new UIListener() {

			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					GameManager.getInstance().m_game_message.sendNpcShopSail(layer, index, num);
					UIManager.getInstance().removeWindow(messageBox);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(messageBox);
				}
			}
		});
	}

	public Object[] getBagDatas()
	{
		return GameManager.getInstance().m_role.m_bag_goods;
	}

	public int getUpIndex()
	{
		switch (this.m_groupId) {
			case GROUP_SAIL_LABEL:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
			case GROUP_SAIL_BAG:
				return m_bag_handler.getCurrentLabelWindowIndex();
		}
		return 0;
	}

	public int getDownIndex()
	{
		switch (this.m_groupId) {
			case GROUP_SAIL_LABEL:
				return getFirstIndex(AbsLBHandler.TYPE_BAG);
			case GROUP_SAIL_BAG:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
		}
		return 0;
	}

	public int getLeftIndex()
	{
		switch (this.m_groupId) {
			case GROUP_SAIL_LABEL:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
			case GROUP_SAIL_BAG:
				return getFirstIndex(AbsLBHandler.TYPE_LABEL) + ActorItemLBHandler.NUM_LABEL_DIS - 1;
		}
		return 0;
	}

	public int getRightIndex()
	{
		switch (this.m_groupId) {
			case GROUP_SAIL_LABEL:
				return getFirstIndex(AbsLBHandler.TYPE_BAG);
			case GROUP_SAIL_BAG:
				return ActorItemLBHandler.TYPE_DIR_UNPRO;
		}
		return 0;
	}

	public int getFirstIndex(int idComp)
	{
		switch (idComp) {
			case AbsLBHandler.TYPE_LABEL:
				return 0;
			case AbsLBHandler.TYPE_BAG:
				return ActorItemLBHandler.NUM_LABEL_DIS;
			default:
				Tools.debugPrintln("无此组Id = " + idComp);
				return 1;
		}
	}

	public int getGroupIndex()
	{
		return m_groupIndex;
	}

	public int getWindowIndex()
	{
		return m_index;
	}

	/*************************/
	// FIX-VARS
	/*************************/
	private void keyLogicOnFix()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			if (m_index == 0) {
				setWindowIndex(1);
			}
			else {
				setWindowIndex(0);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			if (m_index == 0) {
				setWindowIndex(1);
			}
			else {
				setWindowIndex(0);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {

		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {

		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			if (m_index == 0) {
				GameManager.getInstance().m_game_message.sendNpcFixAllEquip();
			}
			else {
				GameManager.getInstance().m_game_message.sendNpcFixAllBag();
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			close();
		}
	}

	/*************************/
	// NUM - LOGIC
	/*************************/

	/**
	 * 通用进入
	 */
	private void gotoNumInput(int max, int defaultNum, ActorItem item)
	{
		if (item == null) {
			Tools.debugPrintln("UINpcShop:程序bug了");
			return;
		}
		m_num_max = max;
		m_num_input = defaultNum;
		m_num_item = item;
		m_num_money = m_num_input * item.m_money_sail;
		setWindowStatus(STATE_NUM);
	}

	/**
	 * 从贩卖道具界面进入 2012-2-29 下午04:43:32 venizeng
	 * @param item
	 */
	private void gotoNumSail(ActorItem item)
	{
		if (item == null) {
			return;
		}
		gotoNumInput(item.m_num, item.m_num, item);
	}

	private void keyLogicOnNum()
	{
		// if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
		// if (m_num_input <= 1) {
		// return;
		// }
		// m_num_input -= 10;
		// m_num_input = m_num_input < 1 ? 1 : m_num_input;
		// changeNumInput(m_num_input);
		// }
		// else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
		// if (m_num_input >= m_num_max) {
		// return;
		// }
		// m_num_input += 10;
		// m_num_input = m_num_input > m_num_max ? m_num_max : m_num_input;
		// changeNumInput(m_num_input);
		// }
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)
				|| AbstractGameScreen.haveKeyHold(AbstractGameScreen.GK_LEFT)) {
			if (m_num_input <= 1) {
				changeNumInput(m_num_max);
			}
			else {
				changeNumInput(m_num_input - 1);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)
				|| AbstractGameScreen.haveKeyHold(AbstractGameScreen.GK_RIGHT)) {
			if (m_num_input >= m_num_max) {
				changeNumInput(1);
			}
			else {
				changeNumInput(m_num_input + 1);
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
			switch (STATE_CURRENT) {
				case STATE_BUY://
					// 发送购买道具指令
					if (m_num_money > GameManager.getInstance().m_role.m_money_game) {
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "游戏币不足");
					}
					else {
						GameManager.getInstance().m_game_message.sendNpcShopBuy(TYPE_SHOP, m_num_item.m_key,
								m_num_input);
						backNumToOther();
					}
					break;
				case STATE_SAIL:
					// 发送贩卖道具指令
					// GameManager.getInstance().m_game_message.sendNpcShopSail(m_num_item.m_layer_actorItem,
					// m_num_item.m_index, m_num_item.m_num);
//					sendSail(m_num_item.m_layer_actorItem, m_num_item.m_index, m_num_item.m_num);
					sendSail(m_num_item);
					backNumToOther();
					break;
				default:
					break;
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
			backNumToOther();
		}
	}

	private void changeNumInput(int num_input)
	{
		m_num_input = num_input;
		m_num_money = m_num_item.m_money_sail * m_num_input;
	}

	private void backNumToOther()
	{
		m_num_item = null;
		m_num_input = 0;
		m_num_max = 0;
		m_num_money = 0;
		setWindowStatus(STATE_CURRENT);
	}

	/*************************/
	// ALL PAINT
	/*************************/
	protected void paintContent(Graphics g)
	{
		paintBackground(g);
		switch (m_state) {
			case STATE_BUY:
				paintBuyItems(g);
				paintBuyPrice(g);
				paintBuyDescribe(g);
				break;
			case STATE_SAIL:
				paintSailLBag(g);
				paintSailPrice(g);
				// paintSailDescribe(g);
				break;
			case STATE_FIX:
				paintFixDescribe(g);
				paintFixButtonRect(g);
				break;
			case STATE_NUM:
				paintNum(g);
				break;
		}
	}

	/**
	 * @绘制当前背景
	 * @同时绘制玩家的金钱信息 2012-2-29 上午10:51:11 venizeng
	 * @param g
	 */
	private void paintBackground(Graphics g)
	{
		UITools.paintBackGround(g, m_x, m_y, m_w, m_h, TITLE);
		int tempX = m_x + m_w - UIManager.getColorsWinBorder().length;
		int tempY = m_y + UITools.ENDY_CONTENT;
//		UITools.paintMoneyGameRB(g, tempX, tempY, GameManager.getInstance().m_role.m_money_game, false);
		if (TYPE_SHOP == ActorRole.ZHANGONG) {
			paintMoney(g, tempX, tempY, GameManager.getInstance().m_role.m_money_zhangong, false);
		}
		else if(TYPE_SHOP == ActorRole.BANGGONG){
			paintMoney(g, tempX, tempY, GameManager.getInstance().m_role.m_money_banggong, false);
		}
		else {
			paintMoney(g, tempX, tempY, GameManager.getInstance().m_role.m_money_game, false);
		}
		// tempY -= (UITools.H_MONEY_GAME + UITools.IH_RECTS);
		// UITools.paintMoneyRmbRB(g, tempX, tempY, GameManager.getInstance().m_role.m_money_rmb,false);
	}

	/**
	 * @绘制通用的价格描述框
	 * @策划确定只表现游戏币，且在买和卖的情况下一致 2012-2-29 上午10:54:49 venizeng
	 * @param g
	 * @param money
	 */
	private void paintMoneyGameRect(Graphics g, long money, int x, int y)
	{
		UITools.paintContentRect(g, x, y, W_PRICE_RECT, H_PRICE_RECT);
		int tempX = x + X_RECT_CONTENT;
		int tempY = y + X_RECT_CONTENT;
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		g.drawString(PRICE, tempX, tempY, 0);
//		UITools.paintMoneyGameRB(g, x + W_PRICE_RECT - UITools.IW_RECT_CONTENT, tempY + AbstractGameScreen.FONT_H,
//				money, false);
		paintMoney(g, x + W_PRICE_RECT - UITools.IW_RECT_CONTENT, tempY + AbstractGameScreen.FONT_H,
				money, false);
	}

	/**
	 * @绘制当前道具的描述框,若有变化可随时变动 2012-2-29 上午10:56:17 venizeng
	 * @param g
	 * @param x
	 * @param y
	 */
	private void paintDescribeRect(Graphics g, int x, int y, int w, int h)
	{
		UITools.paintContentRect(g, x, y, w, h);
	}

	/*************************/
	// BUY-PAINT
	/*************************/

	private void paintBuyItems(Graphics g)
	{
		final int INITX = m_x + X_BUY_ITEM;
		//
		int tempY = m_y + Y_BUY_ITEM;
		int index = 0;
		for (int i = 0; i < NUM_BUY_ROWS; i++) {
			int tempX = INITX;
			for (int j = 0; j < NUM_BUY_COLS; j++) {
				UITools.paintActorItem(g, tempX, tempY, m_items_buy[index], false, m_index == index, true);
				index++;
				tempX += RW_BUY_ITEM;
			}
			tempY += RH_BUY_ITEM;
		}
	}

	private void paintBuyPrice(Graphics g)
	{
		int tempX = m_x + X_BORDER_RECT;
		int tempY = m_y + Y_BUY_PRICE;
		paintMoneyGameRect(g, m_price, tempX, tempY);
	}

	private void paintBuyDescribe(Graphics g)
	{
		int tempX = m_x + X_BORDER_RECT;
		int tempY = m_y + Y_BUY_DESCRIBE;
		int endX = tempX + W_DESCRIBE_RECT - UITools.IW_RECT_CONTENT - 1;
		paintDescribeRect(g, tempX, tempY, W_DESCRIBE_RECT, H_BUY_DESCRIBE);
		int clipX = g.getClipX();
		int clipY = g.getClipY();
		int clipW = g.getClipWidth();
		int clipH = g.getClipHeight();
		tempX += UITools.IW_RECT_CONTENT;
		tempY += UITools.IH_RECT_CONTENT;
		int tempW = W_DESCRIBE_RECT - (UITools.IW_RECT_CONTENT << 1) + 1;
		int tempH = H_BUY_DESCRIBE - (UITools.IH_RECT_CONTENT << 1) + 1;
		g.setClip(tempX, tempY, tempW, tempH);
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		if (m_index < NUM) {
			// 名字
			if (m_items_buy != null && m_items_buy[m_index] != null) {
				g.drawString(m_items_buy[m_index].m_name, tempX, tempY, 0);
			}
			// 类型
			if (m_buy_s_types != null && m_buy_s_types[m_index] != null) {
				// g.drawString(m_buy_s_types[m_index], tempX, tempY, 0);
				int nameW = AbstractGameScreen.s_font.stringWidth(m_items_buy[m_index].m_name) + 5;
				int typeW = AbstractGameScreen.s_font.stringWidth(m_buy_s_types[m_index]);
				if (typeW >= tempW - nameW) {
					typeW = tempW - nameW;
				}
				UITools
						.paintScrollStr(g, endX - typeW, tempY, typeW, AbstractGameScreen.FONT_H,
								m_buy_s_types[m_index]);
//				g.drawString(m_buy_s_types[m_index], endX, tempY, Tools.RIGHT_TOP);
			}
			tempY += H_PRE;
			// 绑定类型
			if (m_buy_s_type_bangdings != null && m_buy_s_type_bangdings[m_index] != null) {
				g.drawString(m_buy_s_type_bangdings[m_index], tempX, tempY, 0);
			}
			// 等级
			if (m_buy_s_pos != null && m_buy_s_pos[m_index] != null) {
				g.drawString(m_buy_s_pos[m_index], endX, tempY, Tools.RIGHT_TOP);
			}
			tempY += H_PRE;
			// 使用限制
			if (m_buy_s_level_limits != null && m_buy_s_level_limits[m_index] != null) {
				g.drawString(m_buy_s_level_limits[m_index], tempX, tempY, 0);
			}
			// 职业限制
			if (m_buy_s_career_limits != null && m_buy_s_career_limits[m_index] != null) {
				g.drawString(m_buy_s_career_limits[m_index], endX, tempY, Tools.RIGHT_TOP);
			}
			tempY += H_PRE;
			// 时间限制
			if (m_buy_s_time_limits != null && m_buy_s_time_limits[m_index] != null) {
				if (m_buy_s_career_limits != null && m_buy_s_career_limits[m_index] != null) {
					tempX += AbstractGameScreen.s_font.stringWidth(m_buy_s_career_limits[m_index]) + 2;
				}
				g.drawString(m_buy_s_time_limits[m_index], endX, tempY, Tools.RIGHT_TOP);
			}
		}
		// 绘制描述
		g.setClip(clipX, clipY, clipW, clipH);
	}

	/*************************/
	// SAIL-PAINT
	/*************************/

	private void paintSailLBag(Graphics g)
	{
		m_bag_handler.setInitXY(m_y + Y_SAIL_LABEL);
		m_bag_handler.paintLabel(g);
		m_bag_handler.paintBag(g);
		m_bag_handler.paintDrag(g);
		m_bag_handler.paintBagFocused(g);
		m_bag_handler.paintDescribe(g);
	}

	private void paintSailPrice(Graphics g)
	{
		int tempX = m_x + X_BORDER_RECT;
		int tempY = m_y + Y_SAIL_LABEL + m_bag_handler.getLBHeight() + UITools.IH_RECT_CONTENT;;
		paintMoneyGameRect(g, m_price, tempX, tempY);
	}

	/*************************/
	// Fix-PAINT
	/*************************/

	private final String STR_FIX_EQUIPS = "修理装备栏装备";
	private final String STR_FIX_ALL = "修理全部装备";

	private void paintFixDescribe(Graphics g)
	{
		int tempX = m_x + X_FIX_DESCRIBE;
		int tempY = m_y + Y_FIX_DESCRIBE;
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		if (STRS_FIX_DESCRIBE == null) {
			return;
		}
		for (int i = 0, length = STRS_FIX_DESCRIBE.length; i < length; i++) {
			if (STRS_FIX_DESCRIBE[i] == null) {
				continue;
			}
			g.drawString(STRS_FIX_DESCRIBE[i], tempX, tempY, 0);
			tempY += H_PRE;
		}
	}

	private void paintFixButtonRect(Graphics g)
	{
		paintDescribeRect(g, m_x + X_FIX_RECT, m_y + Y_FIX_RECT, W_FIX_RECT, H_FIX_RECT);
		boolean isNoOneSel = m_index == 0;
		paintFixButtonAndMoney(g, m_x + X_FIX_BUTTON1, m_y + Y_FIX_BUTTON1, STR_FIX_EQUIPS, m_fix_money_equip, 0,
				isNoOneSel);
		paintFixButtonAndMoney(g, m_x + X_FIX_BUTTON2, m_y + Y_FIX_BUTTON2, STR_FIX_ALL, m_fix_money_all, 1,
				!isNoOneSel);
	}

	private void paintFixButtonAndMoney(Graphics g, int x, int y, String str, long money, int index, boolean isSel)
	{
		UITools.paintLabelStr(g, x, y, W_FIX_BUTTON, H_FIX_BUTTON, str, isSel, isSel);
		UITools.paintMoneyGameRT(g, x + W_FIX_BUTTON, y + H_FIX_BUTTON + UITools.IH_RECTS, money, false);
	}

	final int X_NUM = 20;
	final int Y_NUM = 45;
	final int W_NUM = W_BG - (X_NUM << 1);
	final int H_NUM = H_BG - (Y_NUM << 1);
	final int Y_NUM_ITEM = ((H_BG - H_NUM) >> 1);

	final String STR_NUM_TITILE = "输入数目";
	final String STR_NUM_NUMBER = "数目:";
	final String STR_NUM_PRICE = "价格:";

	/*************************/
	// Num-PAINT
	/*************************/
	private final String TITLE_NUM = "请输入数目";

	private void paintNum(Graphics g)
	{
		int tempX = m_x + X_NUM;
		int tempY = m_y + Y_NUM;
		UITools.drawWindowBackgroud(g, tempX, tempY, W_NUM, H_NUM);
		UITools.paintBackgroundTitleOn240320(g, tempX, tempY, W_NUM, H_NUM, TITLE_NUM); // 绘制标题
		tempX += 20;
		tempY += Y_NUM_ITEM;
		UITools.paintActorItem(g, tempX, tempY, m_num_item);
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_YESS));
		g.drawString(m_num_item.m_name, tempX + 30, tempY, 0);
		// 输入数目
		tempY += H_PRE + 10;
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		g.drawString(STR_NUM_NUMBER, tempX, tempY, 0);
		paintNumInput(g, tempX + AbstractGameScreen.s_font.stringWidth(STR_NUM_NUMBER) + 25, tempY);
		//
		tempY += H_PRE;
		tempY += 10;
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		g.drawString(STR_NUM_PRICE, tempX, tempY, 0);
//		UITools.paintMoneyGameRB(g, m_x + X_NUM + W_NUM - UITools.IW_WIN, tempY + AbstractGameScreen.FONT_H,
//				m_num_money, false);
		paintMoney(g, m_x + X_NUM + W_NUM - UITools.IW_WIN, tempY + AbstractGameScreen.FONT_H, m_num_money, false);
	}

	private void paintNumInput(Graphics g, int x, int y)
	{
		//
		UITools.paintContentRect(g, x, y, W_NUM_INPUT, H_NUM_INPUT);
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_YESS));
		g.drawString(String.valueOf(m_num_input), x + W_NUM_INPUT - UITools.IW_RECT_CONTENT, y
				+ UITools.IH_RECT_CONTENT, Tools.RIGHT_TOP);
		//
		// int tempX = x + ((W_NUM_INPUT - W_DARK) >> 1);
		// Tools.drawRegion(g, UIManager.IMAGE_ARR_DARK, tempX, y - IH_NUM_ARR_RECT, Tools.TRANS_NONE,
		// Tools.LEFT_BOTTOM);// 上
		// Tools.drawRegion(g, UIManager.IMAGE_ARR_DARK, tempX, y + H_NUM_INPUT + H_DARK + IH_NUM_ARR_RECT + 1,
		// Tools.TRANS_V, Tools.LEFT_BOTTOM);// 下
		int tempY = y + ((H_NUM_INPUT + W_DARK) >> 1);
		int tempX = x - IW_NUM_ARR_RECT;
		Tools.drawRegion(g, UIManager.IMAGE_ARR_DARK, x - IW_NUM_ARR_RECT, tempY, Tools.TRANS_90, Tools.LEFT_BOTTOM);// 左
		Tools.drawRegion(g, UIManager.IMAGE_ARR_DARK, x + W_NUM_INPUT + IW_NUM_ARR_RECT - H_DARK + 1, tempY,
				Tools.TRANS_270, Tools.LEFT_BOTTOM);// 右
	}

	private void paintMoney(Graphics g, int x, int y, long money, boolean isSel)
	{
		if (TYPE_SHOP == ActorRole.ZHANGONG) {
			UITools.paintMoneyZhangongRB(g, x, y+2, money, false);
		}
		else if(TYPE_SHOP == ActorRole.BANGGONG){
			UITools.paintMoneyJiagongRB(g, x, y, money, false);
		}
		else {
			UITools.paintMoneyGameRB(g, x, y, money, false);
		}
	}
}
